/******************************************************************************
Project    : Real time rtsp server library base on live555
*******************************************************************************
File Name    :  <RealTimeRtspServer.h>:  real time rtsp server head file
Module Name  :  
Description  :  None
History      :
 No.   Ver.     Date        Designed by  Comment
-----+--------+----------+------------+---------------------------------------
 001   0.00.01  05/25/2015  <3G@LIURENHUA>   <real time rtsp server head file>
*******************************************************************************/
#ifndef _REAL_TIME_RTSP_SERVER_H
#define _REAL_TIME_RTSP_SERVER_H

#include <RTSPServer.hh>
#include <ServerMediaSession.hh>
#include <BasicUsageEnvironment.hh>

/******************************************************************************
  macro define
 ******************************************************************************/
#define DEFAULT_PORT		(8899)

/******************************************************************************
  enum declaration
 ******************************************************************************/
/* rtsp server error identity */
typedef enum _RTSPSVR_ERR_et{
	RTSPSVR_ERR_NOERR = 0,
	RTSPSVR_ERR_SMS,
	RTSPSVR_ERR_ASMSS,
	RTSPSVR_ERR_ASMS,
	RTSPSVR_ERR_TASK
}RTSPSVR_ERR_et;

/******************************************************************************
  class declaration
 ******************************************************************************/
class RealTimeRtspServer
{
public:
	UsageEnvironment *pctGetUsageEnv() const {return pctEnv;}
	RealTimeRtspServer(u_int16_t usPort = 0);
	~RealTimeRtspServer();

	/* Create server media session instance */
	RTSPSVR_ERR_et eCreateSMS(
				char const* pcStrmName = NULL, 
				char const* pcInfo = NULL, 
				char const* pcDescription = NULL, 
				Boolean bIsSSM = False, 
				char const* pcMiscSDPLines = NULL);
	
	/* Add server media subsession to server media session */
	RTSPSVR_ERR_et eAddSMSSToSMS(
				ServerMediaSubsession* pctSMSS);

	/* Add server media session to rtsp server (called multiply) */
	RTSPSVR_ERR_et eAddSMSToRtspSvr();

	/* Get url address of rtsp server (need delete return pointer ) */
	const char *pcGetRtspServerUrl();

	/* Start task scheduler loop (block, call in thread or process) */
	RTSPSVR_ERR_et eStartTaskScheduler();

	/* Closes (from the server) all RTSP client sessions */
	void vResetRtspServer();
	
	/* Stop task scheduler loop */
	void vStopTaskScheduler(){cExitFlag=1;}
	
private:
	static pthread_mutex_t mutex;
	static u_int16_t m_usPort;
	
	TaskScheduler *pctScheduler;
	UsageEnvironment *pctEnv;
	RTSPServer *pctRtspSvr;
	ServerMediaSession *pctSms;
	char cExitFlag;
};
#endif /* _REAL_TIME_RTSP_SERVER_H */
